package com.frank.towerrush.split;

import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

/**
 * 子弹类
 * 
 * @author Frank
 *
 */
public class Bullet extends Location {

    public static List<Bullet> bullets;

    public static void setBulletList(List<Bullet> bullets) {
        Bullet.bullets = bullets;
    }

    public Monster target;
    Bitmap image;
    int dmg;
    int speed;

    public Bullet(Flag loc, Monster target, Bitmap image, int dmg, int speed) {
        super(loc);
        this.target = target;
        this.image = image;
        this.dmg = dmg;
        this.speed = speed;
        setSize(image.getHeight(), image.getWidth());
    }

    /**
     * 子弹移动
     */
    private void move() {
        Flag loc = getLoc();
        Flag to = target.getLoc();
        boolean hit = loc.closeTo(to, speed);
        setLoc(loc);
        if (hit) {
            target.hit(dmg);
            bullets.remove(this);
        }
    }

    public void paint(Canvas canvas, Paint paint) {
        canvas.drawBitmap(image, null, getRectF(), paint);
        move();
    }
}
